package de.lindenvalley.ergo;

import java.util.Locale;

import util.AnotherFont;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class ErgoAppActivity extends Activity implements View.OnClickListener{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start);
        TextView tvSmall = (TextView) findViewById(R.id.textMainSmall);
        tvSmall.setText(Html.fromHtml(getString(R.string.main_text_small)));
        View buttonEnglishStart = findViewById(R.id.imageViewEN);
        View buttonDetchStart = findViewById(R.id.imageViewDE);
        AnotherFont.findTypeface((ViewGroup)getWindow().getDecorView());
        
        TextView logoWebLink = (TextView) findViewById(R.id.imageView2);
        
        buttonEnglishStart.setOnClickListener(this);
        buttonDetchStart.setOnClickListener(this);
        logoWebLink.setOnClickListener(this);
    }

	@Override
	public void onClick(View v) {
		int id = v.getId();
		Locale newLocale = null;
		Configuration configuration = new Configuration();
		
		switch(id){
		case R.id.imageViewEN:
			newLocale = new Locale("en");
			break;
		case R.id.imageViewDE:
			newLocale = new Locale("de");
			break;
		case R.id.imageView2:
			Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.urlLink)));
			startActivity(intent);
			break;
		}
		if (newLocale != null){
			Locale.setDefault(newLocale);
			configuration.locale = newLocale;
			getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
			Intent intent = new Intent (ErgoAppActivity.this, DescriptionActivity.class);
			startActivity(intent);
			finish();
//			Toast.makeText(ErgoAppActivity.this, R.string.hello, Toast.LENGTH_LONG).show();

		}
	}
}